﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebApplication1
{
    public partial class WebForm2 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["name"] == null || Request.Cookies["pwd"] == null)
            {
                Response.Redirect("WebForm1.aspx");
            }
            if (Application["CharRoom"] == null)
            {
                Application["ChatRoom"] = new Panel();
            }
            Panel1.Controls.Add((Panel)Application["ChatRoom"]);
        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            Page_Load(sender,e);
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            string text = TextBox1.Text;
            string name = Session["name"].ToString();
            string nowTime = DateTime.Now.ToString();

            Literal literal = new Literal();
            literal.Text = name + " " + nowTime + " : " + text + "<br/>";

            Panel panel = (Panel)Application["ChatRoom"];
            panel.Controls.Add(literal);
        }

        protected void Button3_Click(object sender, EventArgs e)
        {
            Session.Abandon();
            Response.Redirect("WebForm1.aspx");
        }
    }
}